package reflect;

import java.lang.reflect.Constructor;

public class Test {
    public static void main(String[] args) throws Exception {
        Class cls=Class.forName("reflect.Student");//获取一个类
        Constructor cons1=cls.getConstructor();//获取无参的构造器
        Constructor cons2=cls.getConstructor(String.class,int.class,char.class);//获取有参的构造器
        Object obj1=cons1.newInstance();//无参构造一个对象
        Object obj2=cons2.newInstance("张三", 20, '男');//有参构造一个对象
        System.out.println(obj1);
        System.out.println(obj2);

    }
}
